home *** CD-ROM | disk | FTP | other *** search
- /*
- * File: CItemTable.c
- * Created: 7/25/93
- * Desc:
- *
- * Superclass: CArrayPane.
- * Uses: CItem.
- * Original Author: Atul Barve
- * Modifications: W. Wesley Monroe
- *
- * Copyright © 1993 Animas Software Production. All rights reserved.
- */
-
- #include <TBUtilities.h>
- #include <Icons.h>
- #include <ctype.h>
-
- #include "CTypingTask.h"
- #include "CItemTable.h"
- #include "CItemList.h"
- #include "CItem.h"
- #include "CTableExpander.h"
- #include "CDragDropTableTask.h"
- #include "CExtendDragTask.h"
- #include <Constants.h>
-
- #include <Sound.h>
-
-
- #define kCellFont monaco
- #define kCellFontSize 9
- #define kCellFontStyle 0
- #define kCellLevelIndent 16
- #define kIconWidth 16
- #define kIconHeight 16
- #define kCellHeight 20
- #define kIconIndent 20
- #define kTextIndent 40
- #define deleteKey '\b'
-
- #define kOpenTriangle 133
- #define kCloseTriangle 131
- #define kInterimTriangle 132
-
- extern RgnHandle gUtilRgn;
-
- /*
- * IItemTable
- */
- #define IsRectRgn(rgn) \
- ((rgn) && ((**rgn).rgnSize == sizeof(Region)) && !EmptyRgn( rgn))
-
- void CItemTable::IItemTable( CView *anEnclosure, CBureaucrat *aSupervisor,
- short aWidth, short aHeight,
- short aHEncl, short aVEncl,
- SizingOption aHSizing, SizingOption aVSizing,
- short dragFlag)
- {
- CArrayPane::IArrayPane( anEnclosure, aSupervisor, aWidth, aHeight,
- aHEncl, aVEncl, aHSizing, aVSizing);
-
- fSelItems = new CItemList;
- fSelItems->IItemList();
-
- SetDefaults( -1, kCellHeight);
-
- fDragFlag = dragFlag;
- }
-
- void CItemTable::IViewTemp( CView *anEnclosure, CBureaucrat *aSupervisor,Ptr viewData)
- {
- LongRect r;
- CArrayPane::IViewTemp( anEnclosure, aSupervisor, viewData);
-
- fSelItems = new CItemList;
- fSelItems->IItemList();
- r = frame;
- SetBounds(&r);
-
- }
-
- void CItemTable::SetDragFlag(short flag)
- {
- fDragFlag = flag;
- }
-
- /*
- * GetCellText() {OVERRIDE}
- *
- * Return the cell text from the CItem in a Pascal String
- */
-
- void CItemTable::GetCellText( Cell aCell, short availableWidth, StringPtr itsText)
- {
- CItemList *list;
- CItem *aItem;
-
- ASSERT( member( itsArray, CItemList));
-
- if (itsArray)
- {
- list = (CItemList *) itsArray;
- aItem = (CItem*) list->NthItem( aCell.v+1);
- if(aItem) {
- aItem->GetDisplayText((char*)itsText);
- }
- }
-
- }
-
- enum {
- kArrowCollapsed = 131,
- kArrowTransition,
- kArrowExpanded
- };
-
- void CItemTable::AnimateOpenClose(Cell hitCell)
- {
- LongRect pinRect;
- Rect iconRect;
- short indentLeft;
- CItem *aItem;
- short expanded;
- short ic1,ic2,ic3;
- long ts;
-
- aItem = GetItem(hitCell.v + 1);
-
- if(aItem) {
- GetCellRect(hitCell,&pinRect);
-
- expanded = aItem->GetExpanded();
-
- iconRect.bottom = iconRect.top = (pinRect.bottom + pinRect.top) / 2 - 8;
- iconRect.right = iconRect.left = pinRect.left + indent.h;
- iconRect.right += 16;
- iconRect.bottom += 16;
-
- expanded = aItem->GetExpanded();
- if(expanded) {
- ic1 = kArrowCollapsed;
- ic3 = kArrowExpanded;
- }
- else {
- ic3 = kArrowCollapsed;
- ic1 = kArrowExpanded;
- }
-
- Prepare();
- EraseRect(&iconRect);
- ic2 = kArrowTransition;
- DrawTriangle(&iconRect, 0, ic1);
- ts = TickCount();
- while(ts + 5 > TickCount());
- DrawTriangle(&iconRect, 0, ic2);
- ts = TickCount();
- while(ts + 5 > TickCount());
- DrawTriangle(&iconRect, 0, ic3);
- }
- }
-
- void CItemTable::DrawTriangle(Rect *cellRect,short indentLeft,short id)
- {
- EraseRect(cellRect);
- Draw7Icon(cellRect,indentLeft,id,ttNone);
- }
-
- /*
- * GetCanRecieve()
- *
- * Can the table recieve dropped objects?
- */
-
- Boolean CItemTable::GetCanRecieve(void)
- {
- return selectionFlags & selCanRecieve;
- }
-
- /*
- * Draw7Icon()
- *
- * Draw the Item icon centered in the middle of the cell.
- */
-
- void CItemTable::Draw7Icon(Rect *cellRect, short indentLeft,
- short id, short xfer)
- {
- short mid;
- Rect iRect;
- CIconHandle hndl;
- Handle iSuite = 0;
-
-
- mid = (cellRect->bottom + cellRect->top) / 2;
-
- iRect.top = mid - 8;
- iRect.bottom = iRect.top + 16;
- iRect.left = indent.h + indentLeft;
- iRect.right = iRect.left + 16;
-
- PlotIconID(&iRect, atNone, xfer, id);
- }
-
- /*
- * DrawCell()
- *
- * Draw:
- * - the expando icon if its a parent cell
- * - the item icon if it has one
- * - the text of the item
- */
-
- void CItemTable::DrawCell( Cell theCell, Rect *cellRect)
- {
- Str255 cellText;
- short availWidth;
- CItem *aItem;
- CItemList *list;
- short levelIndent;
- short numSubs;
- short y;
-
- ASSERT(member(itsArray,CItemList));
-
- list = (CItemList*) itsArray;
-
- aItem = (CItem*) list->NthItem(theCell.v + 1);
-
- ASSERT(aItem);
-
- levelIndent = aItem->GetLevel() * kCellLevelIndent;
-
- numSubs = aItem->GetNumSubItems();
-
- availWidth = cellRect->right - cellRect->left - indent.h;
-
-
- GetCellText( theCell, availWidth, cellText);
-
- y = ((cellRect->bottom - cellRect->top) - ( fontInfo.ascent)) / 2;
- if (cellText[0] > 0)
- {
- if(aItem && aItem->GetExpanded() && numSubs)
- Draw7Icon(cellRect, 0,kOpenTriangle, ttNone);
- else if(aItem && numSubs)
- Draw7Icon(cellRect, 0,kCloseTriangle, ttNone);
-
- Draw7Icon(cellRect, levelIndent + kIconIndent, aItem->GetIconID(), ttNone);
- MoveTo( cellRect->left + indent.h + levelIndent + kTextIndent, cellRect->bottom - y);
- DrawString( cellText);
- }
- }
-
- /*
- * ExpandCell()
- *
- * Expand or Close a parent item.
- */
-
- void CItemTable::ExpandCell(Cell theCell,short expand)
- {
- CItem *aItem,*sub,*pSub;
- CItemList *list;
- short numSubViews;
- short i;
- Handle sndHndl;
-
- ASSERT(member(itsArray,CItemList));
-
- list = (CItemList*) itsArray;
-
- aItem = (CItem*)list->NthItem(theCell.v + 1);
-
- ASSERT(aItem);
-
- numSubViews = aItem->GetNumSubItems();
- pSub = aItem;
-
- sndHndl = Get1Resource('snd ',128);
- if(sndHndl)
- SndPlay(0,sndHndl,0);
- for(i=1;i<=numSubViews;i++) {
- sub = aItem->GetNthSubItem(i);
- if(expand) {
- list->InsertAfter(sub,pSub);
- pSub = sub;
- }
- else {
- list->RemoveFromVisTree(sub);
- pSub = sub;
- }
- }
-
- BroadcastChange(itemTableItemExpanded, aItem);
- }
-
- /*
- * RemoveSubviews()
- *
- * Delete references to the selectedItems in the
- * parents subview list.
- */
-
- void CItemTable::RemoveSubviews(CItemList *selectedItems)
- {
- CItem *itemToRemove, *parent;
- short i, nItems = selectedItems->GetNumItems();
- long ndx;
-
- for(i = 1; i <= nItems; i++) {
-
- itemToRemove = (CItem *) selectedItems->NthItem(i);
-
- parent = itemToRemove->GetParent();
- if(parent)
- parent->RemoveSubItem(itemToRemove);
-
- // Remove items from what is visible
- // on the screen...
- ((CItemList *) itsArray)->RemoveFromVisTree(itemToRemove);
-
- }
- }
-
- void CItemTable::GraftItems(CItem *parent, CItemList *selectedItems)
- {
- CItem *itemToGraft;
-
- short i, nItems = selectedItems->GetNumItems();
-
- for(i = 1; i <= nItems; i++) {
-
- itemToGraft = (CItem *) selectedItems->NthItem(i);
-
- // Set the new daddy...
- if(parent) {
-
- itemToGraft->SetParent(parent);
- // itemToGraft->SetLevel(parent->GetLevel() + 1);
- itemToGraft->SetExpanded(parent->GetExpanded());
- parent->GraftSubItem(itemToGraft);
-
- // now put it in the visible list...
- if(parent->GetExpanded()) {
- Cell pCell = {0, 0};
-
- pCell.v = ((CItemList *) itsArray)->Offset(parent);
- ExpandCell(pCell, FALSE);
- ExpandCell(pCell, TRUE);
- }
- BroadcastChange(itemTableItemAdded, itemToGraft);
- } else
- AddItemToRoot(itemToGraft);
-
- }
- Refresh();
- }
-
- void CItemTable::AddItemToRoot(CItem *itemToGraft)
- {
- itemToGraft->SetParent(0L);
- itemToGraft->SetLevel(0);
- itemToGraft->SetExpanded(FALSE);
-
- ((CItemList *) itsArray)->Append(itemToGraft);
- BroadcastChange(itemTableItemAdded, itemToGraft);
- }
-
- /*
- * MakeMouseTask()
- *
- * Return the appropriate type of task depending
- * on if the user selected in the expand icon
- * or the item itself.
- */
-
- CMouseTask *CItemTable::MakeMouseTask(short modifiers)
- {
- CTableExpander *tblTask;
- CDragDropTableTask *tblTask2;
- CTableDragger *tblTask3;
- CItem *aItem;
- CItemList *list;
-
- LongPt pt;
- LongRect pinRect;
- Point hitPt;
- Rect iRect;
- Cell hitCell;
- short expanded, indentLeft, inOut, numSubs;
- Rect draggingRect;
- Rect iconRect,textRect,triRect;
- char text[256];
- short canExpand;
- CExtendDragTask *tblTask4;
-
- GetMouse(&hitPt);
- QDToFrame(hitPt, &pt);
-
- ASSERT(member(itsArray,CItemList));
-
- list = (CItemList *) itsArray;
-
- tblTask = NULL;
-
- if(PtInLongRect( &pt, &bounds))
- {
- FindHitCell( &pt, &hitCell);
-
- GetCellRect(hitCell,&pinRect);
-
- aItem = (CItem*)list->NthItem(hitCell.v + 1);
- ASSERT(aItem);
- expanded = aItem->GetExpanded();
- indentLeft = aItem->GetLevel()*kCellLevelIndent;
-
- iRect.bottom = iRect.top = (pinRect.bottom + pinRect.top) / 2 - 8;
- // iRect.right = iRect.left = pinRect.left + indent.h + indentLeft;
- iRect.right = iRect.left = pinRect.left + indent.h;
- iRect.right += 16;
- iRect.bottom += 16;
-
- iconRect = iRect;
- iconRect.left += kIconIndent;
- iconRect.right = iconRect.left + kIconWidth;
-
- textRect = iRect;
-
- textRect.left += kTextIndent;
- aItem->GetDisplayText(text);
- textRect.right = textRect.left + StringWidth(text);
-
- triRect = iRect;
-
-
-
- numSubs = aItem->GetNumSubItems();
- inOut = PtInRect(hitPt, &iRect);
- canExpand = inOut && numSubs;
-
- if(PtInRect(hitPt,&textRect) == 0 &&
- PtInRect(hitPt,&iconRect) == 0 &&
- canExpand == 0 ) {
- CView *mainView;
-
-
- mainView = itsEnclosure;
- tblTask4 = new CExtendDragTask;
- tblTask4->IExtendDragTask(this, mainView, modifiers, selectionFlags);
- return tblTask4;
-
- }
- else if(inOut == 0 || numSubs == 0) {
- CView *mainView;
-
- if(!(selectionFlags & selCanDrag))
- return inherited::MakeMouseTask(modifiers);
-
- mainView = itsEnclosure;
- tblTask2 = new CDragDropTableTask;
- tblTask2->IDragDropTableTask(this, mainView, modifiers, selectionFlags);
- return tblTask2;
- }
- else {
- tblTask = new CTableExpander;
- tblTask->ITableExpander(this, modifiers, selectionFlags,
- aItem, iRect);
- return tblTask;
- }
- }
- return 0;
- } /* CItemTable::MakeMouseTask */
-
- /*
- * GetItem()
- *
- * Return the item in row,
- * NOTE: row is a 1 based index!!!!
- */
-
- CItem *CItemTable::GetItem(short row)
- {
- CItemList *list;
- CItem *aItem;
-
- if(itsArray == 0)
- return 0;
-
- ASSERT(member(itsArray,CItemList));
-
- list = (CItemList*) itsArray;
-
- aItem = (CItem*)list->NthItem(row);
- return aItem;
- }
-
- /*
- * TrackMouse() {OVERRIDE}
- *
- * Reset the clipRect to the window rect so that
- * the gray region can be moved outside the window region
- */
-
- void CItemTable::TrackMouse(CMouseTask *theTask, LongPt *startPt,
- LongRect *pinRect)
- {
- LongPt currPt;
- LongPt prevPt;
-
- EventRecord macEvent;
- Point qdPt;
- Rect clipR;
- Boolean doClip;
-
- clipR = macPort->portRect;
-
- Prepare();
-
- doClip = (selectionFlags & selCanDrag) || (selectionFlags & selCanRecieve) &&
- (fDragFlag != kDragInPaneOnly);
- if(doClip)
- ClipRect(&clipR);
-
- theTask->BeginTracking( startPt);
- currPt = prevPt = *startPt;
-
- while (StillDown()) { /* Track while button is pressed */
-
- /* ??? We could call WaitNextEvent */
- /* here to give background apps */
- /* some CPU time. However, this */
- /* makes mouse tracking a little */
- /* bit sluggish. */
- Prepare();
- if(doClip)
- ClipRect(&clipR);
-
- GetMouse(&qdPt);
- QDToFrame( qdPt, &currPt);
-
- if(!doClip)
- PinInRect(pinRect, &currPt);
- else {
- QDToLongRect(&clipR, pinRect);
- PinInRect(pinRect, &currPt);
- }
-
- theTask->KeepTracking( &currPt, &prevPt, startPt);
- prevPt = currPt;
- }
-
- Prepare();
- if(doClip)
- ClipRect(&clipR);
-
- if (OSEventAvail(mUpMask, &macEvent)) {
- qdPt = macEvent.where;
- GlobalToLocal(&qdPt);
- QDToFrame( qdPt, &currPt);
- }
-
- PinInRect( pinRect, &currPt);
- theTask->EndTracking( &currPt, &prevPt, startPt);
- }
-
- Boolean CItemTable::HasSelection(void)
- {
- return EmptyRgn(itsSelection);
- }
-
- void CItemTable::Hilite( Rect *cells, Boolean hiliteFlag)
- {
- LongRect pixels;
- Rect visPixels;
- CItem *aItem;
- short indentLevel;
- short width;
- char text[256];
- PenState savePen;
- CIconHandle hndl;
- RgnHandle tmp;
-
- GetPenState(&savePen);
- if (!printing)
- {
- CellsToPixels( cells, &pixels); /* get the pixels spanning the cells */
- aItem = GetItem(cells->top + 1);
- indentLevel = pixels.left;
- if(aItem) {
- aItem->GetDisplayText(text);
- TextFont(kCellFont);
- TextSize(kCellFontSize);
- width = StringWidth(text);
- indentLevel = aItem->GetLevel() * kCellLevelIndent;
- }
- // pixels.left = (pixels.left < indentLevel) ? indentLevel + 42 : pixels.left;
- pixels.left = indentLevel + 42; // past the icon to the text;
- if ( SectAperture( &pixels, &visPixels))
- {
- if(aItem) {
- if(hiliteFlag)
- Draw7Icon(&visPixels, indentLevel + 20, aItem->GetIconID(),
- ttSelected);
- else
- Draw7Icon(&visPixels, indentLevel + 20, aItem->GetIconID(),
- ttNone);
- }
-
- PenPat(black);
- // SetHiliteMode();
- visPixels.right = visPixels.left + width;
- InsetRect(&visPixels, 0, 2);
- InvertRect( &visPixels);
- }
- }
- SetPenState(&savePen);
- }
-
- void CItemTable::Draw( Rect *area)
- {
- Cell topLeftCell, botRightCell, currCell;
- short i;
- Rect selectedCells, theCells;
- LongRect r;
- Boolean doCellHilite, reallyActive;
-
- QDToFrameR( area, &r);
-
- if (!SectLongRect( &r, &bounds, &r))
- return;
-
- /* account for topLeftIndent */
-
- r.left = Max( r.left, topLeftIndent.h);
- r.top = Max( r.top, topLeftIndent.v);
-
- r.right--;
- r.bottom--;
-
- /* find bounding cells of redraw rect */
-
- FindHitCell( &topLeftL(r), &topLeftCell);
- FindHitCell( &botRightL(r), &botRightCell);
-
- topLeft(theCells) = topLeftCell;
- botRight( theCells) = botRightCell;
- theCells.bottom++; theCells.right++;
- DrawBorders( &theCells);
-
- reallyActive = IsActive();
- doCellHilite = reallyActive && !IsRectRgn( itsSelection);
-
- FrameToQDR( &aperture, &qdClip);
-
- if (drawOrder == tblRow)
- {
- for ( i = topLeftCell.v; i <= botRightCell.v; i++)
- DrawRow( i, topLeftCell.h, botRightCell.h, doCellHilite);
- }
- else if (drawOrder == tblCol)
- {
- for ( i = topLeftCell.h; i <= botRightCell.h; i++)
- DrawCol( i, topLeftCell.v, botRightCell.v, doCellHilite);
- }
-
- if (clipToCells)
- {
- ForceNextPrepare();
- Prepare();
- }
-
- reallyActive = 1;
-
- if (reallyActive)
- {
- selectedCells = (**itsSelection).rgnBBox;
- if (SectRect( &theCells, &selectedCells, &selectedCells)) {
-
- for (theCells.top = selectedCells.top; theCells.top < selectedCells.bottom; theCells.top++) {
- theCells.bottom = theCells.top + 1;
- for (theCells.left = selectedCells.left; theCells.left < selectedCells.right; theCells.left++) {
- theCells.right = theCells.left + 1;
- Hilite( &theCells, TRUE);
- }
- }
- }
- }
-
-
- } /* CTable::Draw */
-
- /*
- * GetHiliteRgn()
- *
- * Get the hilite region, and return a list with references to
- * the selected CItems.
- */
-
- CItemList *CItemTable::GetHiliteRgn(RgnHandle *rgnHdl)
- {
- CItemList *itemList;
- CItem *aItem;
-
- LongRect pinRect;
-
- Rect cellRect, r;
- RgnHandle cellRgn;
- Cell hitCell;
- Rect iconRect, cRect, iRect, bRect;
-
- short indentLeft;
- char text[256];
-
- itemList = new CItemList;
- itemList->IItemList();
-
- pinRect = bounds;
-
- LongToQDRect(&pinRect,&bRect);
-
- cellRgn = GetSelection();
- *rgnHdl = NewRgn();
- // fSelItems->Dispose();
- if (!EmptyRgn( cellRgn)) {
-
- cellRect = (**cellRgn).rgnBBox;
- OpenRgn();
-
- for (r.top = cellRect.top; r.top < cellRect.bottom; r.top++) {
-
- r.bottom = r.top + 1;
- for (r.left = cellRect.left; r.left < cellRect.right; r.left++)
- {
- r.right = r.left + 1;
- if (PtInRgn( topLeft( r), cellRgn)) {
-
- aItem = GetItem(r.top + 1);
- itemList->Append(aItem);
-
- // fSelItems->Append(aItem);
-
- hitCell.v = r.top;
- hitCell.h = 0;
-
- GetCellRect(hitCell,&pinRect);
-
- LongToQDRect(&pinRect,&cRect);
-
- aItem->GetDisplayText(text);
- indentLeft = aItem->GetLevel()*kCellLevelIndent;
-
- // Calculate the icon rectangle. It is centered
- // in the selected cell, and indeted to indentLeft.
- iRect.bottom = iRect.top =
- (pinRect.bottom + pinRect.top) / 2 - 8;
- iRect.right = iRect.left = pinRect.left + indent.h +
- indentLeft;
- iRect.right += 16;
- iRect.bottom += 16;
-
- iconRect = iRect;
- iconRect.left += 20;
- iconRect.right += 20;
-
- cRect.left = iconRect.right + 2;
- cRect.right = cRect.left + StringWidth(text);
- FrameRect(&iconRect);
- FrameRect(&cRect);
- }
- }
- }
- CloseRgn(*rgnHdl);
- }
-
- return itemList;
- }
-
- Boolean CItemTable::HitInDrag(Cell aCell)
- {
- return PtInRgn(aCell, itsSelection);
- }
-
- /*
- * DropedSameParent()
- *
- * Return true if theItem parent is same parent
- * as the item in dropCell.
- */
-
- Boolean CItemTable::DropedSameParent(short dropCell, CItem *theItem)
- {
- CItem *parent;
-
- if(theItem->GetParent() == 0L)
- return FALSE;
-
- parent = GetItem(dropCell);
-
- return parent == theItem->GetParent();
- }
-
- Boolean CItemTable::ItemCanAcceptDrop(Cell hitCell, CItemList *selectedItems)
- {
- CItem *theItem;
- Rect r;
-
- // Send a Can Accept message to the hit Cell.
- r = tableBounds;
- if(PtInRect(hitCell, &r)) {
- theItem = GetItem(hitCell.v + 1);
- ASSERT(theItem);
- return theItem->CanAccept(selectedItems);
- } else
- return TRUE;
- }
-
- /******************************************************************************
- DeselectRect
-
- Deselect a rectangular region of cells.
- ******************************************************************************/
-
- void CItemTable::DeselectRect(Rect *deselectRect, Boolean redraw)
- {
- Rect realCells, r, visPixels, cellRect;
- LongRect pixels;
-
- /* first clip selectRect to intersection with tableBounds */
-
- if (SectRect( deselectRect, &tableBounds, &realCells))
- {
- /* only deselect cells that were actually selected */
-
- RectRgn( gUtilRgn, &realCells);
- SectRgn( itsSelection, gUtilRgn, gUtilRgn);
- if (!EmptyRgn( gUtilRgn))
- {
- DiffRgn( itsSelection, gUtilRgn, itsSelection);
- if (redraw)
- {
- Prepare();
- cellRect = (**gUtilRgn).rgnBBox;
- for (r.top = cellRect.top; r.top < cellRect.bottom; r.top++)
- {
- r.bottom = r.top + 1;
- for (r.left = cellRect.left; r.left < cellRect.right; r.left++)
- {
- r.right = r.left + 1;
- if (PtInRgn( topLeft( r), gUtilRgn))
- Hilite( &r, FALSE);
- }
- }
- }
- }
-
- BroadcastChange( tableSelectionChanged, NULL);
- }
-
- } /* CTable::DeselectRect */
-
- void CItemTable::HiliteCellRegion( RgnHandle cellRgn, Boolean fHilite)
- {
- Rect cellRect;
- Rect r;
-
- if (!EmptyRgn( cellRgn))
- {
- cellRect = (**cellRgn).rgnBBox;
- for (r.top = cellRect.top; r.top < cellRect.bottom; r.top++)
- {
- r.bottom = r.top + 1;
- for (r.left = cellRect.left; r.left < cellRect.right; r.left++)
- {
- r.right = r.left + 1;
- if (PtInRgn( topLeft( r), cellRgn))
- Hilite( &r, fHilite);
- }
- }
- }
-
- } /* CTable::HiliteCellRegion */
-
- void CItemTable::ExpandCollaspeSelection(short expandColaspe)
- {
- CItem *aItem;
- Rect selectRect;
- Cell theCell;
- short i,n;
-
- theCell.h = 0;
-
- selectRect = (**itsSelection).rgnBBox;
- fSelItems->DeleteItems();
- theCell.v = selectRect.top;
- for(theCell.v = 0;theCell.v < bounds.bottom;theCell.v++) {
- if(PtInRgn(theCell,itsSelection)) {
- aItem = GetItem(theCell.v + 1);
- if(aItem && ((aItem->GetExpanded() == 0 && expandColaspe) ||
- aItem->GetExpanded() && expandColaspe == 0)) {
- aItem->SetExpanded(expandColaspe);
- fSelItems->Append(aItem);
- }
- }
- }
- n = fSelItems->GetNumItems();
- while(n > 0) {
- aItem = (CItem*) fSelItems->FirstItem();
- theCell.v = ((CItemList*)itsArray)->Offset(aItem);
- AnimateOpenClose(theCell);
- ExpandCell(theCell,expandColaspe);
- fSelItems->DeleteItem(1);
- n--;
- }
- selectRect.bottom = selectRect.top +1;
- selectRect.right = selectRect.left +1;
- RectRgn(itsSelection,&selectRect);
- }
-
- void CItemTable::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
- {
-
- switch(theChar) {
- case deleteKey:
- DeleteSelectedItems();
- break;
- default:
- if(isprint(theChar))
- DoTyping(theChar);
- else if(keyCode == KeyLeftCursor &&
- (macEvent->modifiers & cmdKey)) // Close the Selected Cell
- ExpandCollaspeSelection(0);
- else if(keyCode == KeyRightCursor &&
- (macEvent->modifiers & cmdKey)) // Open the Selected Cell
- ExpandCollaspeSelection(1);
- else
- inherited::DoKeyDown(theChar, keyCode, macEvent);
- break;
- }
- }
-
- void CItemTable::DoTyping(char theChar)
- {
- CTypingTask *aTask;
-
- if(fTypingTask && !fTypingTask->CanStillType()) {
-
- // Throw the task away if too much time has passed...
- ForgetObject(fTypingTask);
-
- }
-
- if(!fTypingTask) {
-
- aTask = new CTypingTask;
- aTask->ITypingTask(this, 128);
- fTypingTask = aTask;
- // Notify(aTask);
- } else
- aTask = fTypingTask;
-
- aTask->DoTyping(theChar);
- }
-
- #include <string.h>
-
- Boolean Find_First(CObject *theItem, long buff); /* (CItem *, char *) */
-
- Boolean Find_First(CObject *theItem, long buff)
- {
- CItem *i = (CItem *) theItem;
- char str[128], *b = (char *) buff;
-
- short j, end;
-
- i->GetDisplayText(str);
-
- end = b[0] < str[0] ? b[0] : str[0];
- for(j = 1; j <= end; j++)
- if(b[j] != tolower(str[j]))
- return FALSE;
-
- return TRUE;
- }
-
- void CItemTable::SelectMatchingText(char *buff)
- {
- CItem *matchItem;
- CItemList *aList;
-
- ASSERT(itsArray);
-
- aList = (CItemList *) itsArray;
-
- matchItem = 0L;
- matchItem = (CItem *) aList->FirstSuccess1(Find_First, (long) buff);
-
- if(matchItem) {
-
- Cell hCell = {0, 0};
- long i = aList->FindIndex(matchItem);
-
- hCell.v = i - 1;
- SelectCell(hCell, FALSE, TRUE);
- }
- }
-
- void CItemTable::DeleteSelectedItems(void)
- {
- CItem *anItem, *parent;
- Rect selItems = (**itsSelection).rgnBBox;
- long i;
-
- ASSERT(itsArray && member( itsArray, CItemList));
-
- for(i = selItems.top; i < selItems.bottom; i++) {
- // First remove the subview from the parent
- anItem = GetItem((short) i + 1);
- parent = anItem->GetParent();
-
- if(parent)
- parent->RemoveSubItem(anItem);
-
- // Now delete the item from the list
- itsArray->DeleteItem(i + 1);
- BroadcastChange(itemTableItemRemoved, 0);
-
- anItem->Dispose();
- }
- }
-
- void CItemTable::GetCellRect(Cell theCell, register LongRect *cellRect)
- {
- CItem *aItem;
- char text[256];
- short indentLevel;
-
- inherited::GetCellRect(theCell,cellRect);
- return;
- if ( PtInRect( theCell, &tableBounds)) {
- aItem = GetItem(theCell.v + 1);
- if(aItem == 0)
- return;
- aItem->GetDisplayText(text);
- if(aItem) {
- width = StringWidth(text) + kCellLevelIndent;
- indentLevel = 20 + aItem->GetLevel() * kCellLevelIndent;
- cellRect->right = cellRect->left = indentLevel;
- cellRect->right += width;
- }
- }
-
- } /* CTable::GetCellRect */
-
-
- void CItemTable::CreateTextEnvironment( void)
- {
- CTextEnvirons *textEnvirons;
- TextInfoRec textInfo;
-
- textEnvirons = new( CTextEnvirons);
- itsEnvironment = textEnvirons;
- textEnvirons->ITextEnvirons();
-
- textInfo.fontNumber = kCellFont;
- textInfo.theSize = kCellFontSize;
- textInfo.theStyle = kCellFontStyle;
- textInfo.theMode = srcOr;
-
- textEnvirons->SetTextInfo( &textInfo);
-
- } /* CTable::CreateTextEnvironment */
-